﻿using System;
using System.Collections.Generic;

namespace IceDog.DNF.Program.Poker.Client.Cli
{
    /// <summary>
    /// 游戏平台
    /// </summary>
    public class Launch
    {
        /// <summary>
        /// 运行游戏
        /// </summary>
        public static void RunGame()
        {
            var newLine = "\r\n";
            var str = $"卡莉卡牌：一种新奇的卡牌玩法{newLine}";
            str += $"当您手里的7张牌花色一样时，您就胜利啦{newLine}";
            str += $"---------------------------------{newLine}";
            Console.WriteLine(str);
            string input = Helper.GetRightInput("请输入玩家数量：（2-7）：", new[] { "2", "3", "4", "5", "6", "7" });
            int choices = -1;
            choices = Int32.Parse(input);

            var playerList = new List<Player>(choices);
            for (int i = 1; i < choices + 1; i++)
            {
                var name = $"player{i}";
                Console.WriteLine($"玩家 {i}，请输入您的名字(直接回车则为 {name}:");
                
                var nameVal = Console.ReadLine();
                if (!string.IsNullOrEmpty(nameVal))
                {
                    name = nameVal.Trim();
                }
                playerList.Add(new Player(name));
            }

            Game game = new Game();

            game.SetPlayerList(playerList);
            int whoWin = game.PlayGame();
            if (whoWin == -1)
            {
                Console.WriteLine("抱歉，游戏发生了错误。");
            }
            else
            {
                Console.WriteLine($"玩家 {playerList[whoWin].Name} 赢得了比赛 ^-^");
            }

        }
    }
}
